import { NetService } from '@core/http'
import { Injectable } from '@angular/core'
import { of } from 'rxjs'

import customerUserList from '../../assets/json/customer.json'
import customerLevelList from '../../assets/json/customer-level.json'
import customerAssetsList from '../../assets/json/customer-assets.json'
import customerViewData from '../../assets/json/customer-view.json'
import customerDetailcontact from '../../assets/json/customer-detailcontact.json'
import customerMyassignList from '../../assets/json/customer-myassign.json'
import customerTagUser from '../../assets/json/customer-tag-user.json'
import customerTagRecord from '../../assets/json/customer-tag-record.json'

import { customerController } from '../config/service/customer.controller.js'
import { costomermarketController } from '../config/service/costomermarket.controlller.js'
import { costomeractivityController } from '../config/service/customeractivity.controller.js'

import { tap } from 'rxjs/operators'
@Injectable()
export class ApiService {
  constructor(private net: NetService) {}

  public getCustomerData(id) {
    return this.net.send({
      service: customerController.getCustomerData,
      params: {
        key: id
      }
    })
  }
  /**
   * 获取客户lp b
   */
  public getCustomerList(cursor?) {
    return this.net.send({
      service: customerController.getCustomerList,
      cursor
    })
  }

  public saveQuery(cursor?) {
    return this.net.send({
      service: customerController.saveQuery,
      cursor
    })
  }

  /**
   * 新增分配
   */
  public senddistribute(param) {
    return this.net.send({
      service: customerController.senddistribute,
      params:param
    })
  }

  /**
   * 编辑分配
   */
  public editcuctomerAssign(param,editRrecordno){
    return this.net.send({
      service: customerController.editcuctomerAssign,
      params:param,
      append:[editRrecordno]
    })
  }
  /**
   * 获取客户事件列表
   */
  public getCustomerEventList(cursor?) {
    return this.net.send({
      service: customerController.getCustomerEventList,
      cursor
    })
  }

  // public getCustomerGroupList() {
  //   return this.net.send({
  //     service: customerController.getCustomerGroupList
  //   })
  // }

  public getcustomerLevelList() {
    return of(customerLevelList)
  }
  public getcustomerLevelChangelevel() {
    return this.net.send({
      service:customerController.getCustomerLevelChangelevelList
    })
    // return of(customerLevelList)
  }
  public getcustomerAssetsList() {
    return of(customerAssetsList)
  }

  public getCustomerTagList(type?, parent?) {
    return this.net.send({
      service: customerController.getCustomerTagList
    })
    // return of(
    //   customerTagList
    //     .filter(x => type === undefined || x.type === type)
    //     .filter(x => parent === undefined || x.parent === parent)
    // )
  }

  // public getTagDetail(id) {
  //   return this.net.send({
  //     service: customerController.getCustomerTagList
  //   })
  //   // return of(customerTagList.find(x => x.id.toString() === id.toString()))
  // }

  public getCustomerViewData() {
    return of(customerViewData)
  }

   /**
   * 获取客户详情
   */
  public getcostomerDetaildkList(code) {
    return this.net.send({
      service: customerController.getcostomerDetaildkList,
      append:[code]
    })
  }

  /**
   * 客户参与营销活动记录
   */
  public getcustomerMarketActivity(code){
    return this.net.send({
      service: costomeractivityController.getcustomerMarketActivity,
      append:[code]
    })
  }
  /**
   * 客户交易列表
   */
  public getcustomerTransaction(){
    return this.net.send({
      service: customerController.getcustomerTransaction,
    })
  }

  /**
   * 获取客户账户资产
   */
  public getcustomerAssets(code){
    return this.net.send({
      service: customerController.getcustomerAssets,
      append:[code]
    })
  }
  /**
   * 查询持有产品
   */
  public getcustomerProductList(code){
    return this.net.send({
      service: customerController.getcustomerProductList,
      append:[code]
    })
  }

  /**
   * 持有产品自定义查询
   */
  public getcusProduct(cursor?){
    return this.net.send({
      service: customerController.getcusProduct,
      cursor
    })
  }

  /**
   * 推荐产品列表
   */
  public getRecommProduct(code){
    return this.net.send({
      service: costomermarketController.getRecommProduct,
      params:{
        "index": 0,
        "size": 10,
        "condition":{
          "riskLevelCode":code
        }
      }
    })
  }

  /**
   *  查询客户标签列表
   */
  public getcustomerTagList(cursor?){
    return this.net.send({
      service: customerController.getcustomerTagList,
      cursor
    })
  }

  /**
   * 获取标签一级目录参数
   */
  public getTagCate(cursor?){
    return this.net.send({
      service: customerController.getTagCate,
      cursor
    })
  }

  /**
   * 获取分配记录
   */
  public getcuctomerAssignList(cursor?){
    return this.net.send({
      service: customerController.getcuctomerAssignList,
      cursor
    })
  }

  public getCustomerRankList(cursor?) {
    return this.net.send({
      service: customerController.getCustomerRankList,
      cursor
    })
  }
  public getcustomerDetailcontact(code) {
    return this.net.send({
      service: customerController.getcustomerDetailcontact,
      append:[code]
    })
    return of(customerDetailcontact)
  }

  /**
   * 客户申领列表
   */
  public getCustomerSelectList(cursor?) {
    return this.net.send({
      service: customerController.getCustomerSelectList,
      cursor
    })
  }

  /**
   * 删除客户申领
   */
  public deleteApply(receiveno){
    return this.net.send({
      service: customerController.deleteApply,
      append:[receiveno]
    })
  }

  /**
   * 修改申领
   */
  public editApply(param,receiveno){
    return this.net.send({
      service: customerController.editApply,
      params:param,
      append:[receiveno]
    })
  }

  public lookApply(receiveno){
    return this.net.send({
      service: customerController.lookApply,
      append:[receiveno]
    })
  }

  public getcustomerMyassignList() {
    return of(customerMyassignList)
  }


  /**
   * 删除客户分配列表
   */
  public deletecuctomerAssign(recordno){
    return this.net.send({
      service: customerController.deletecuctomerAssign,
      append:[recordno]
    })
  }

  /**
   * 客户视图资产 年龄  性别 交易类型
   */
  public getCusAssets(){
    return this.net.send({
      service: customerController.getCusAssets,
    })
  }

  public getCusAction(){
    return this.net.send({
      service: customerController.getCusAction,
    })
  }

  public getCusAge(){
    return this.net.send({
      service: customerController.getCusAge,
    })
  }

  public getCusSex(){
    return this.net.send({
      service: customerController.getCusSex,
    })
  }

  /**
   * 查询分配
   */
  public lookcuctomerAssign(recordno){
    return this.net.send({
      service: customerController.lookcuctomerAssign,
      append:[recordno]
    })
  }

  public getCustomerTagUserList() {
    return of(customerTagUser)
  }
  public getCustomerTagRecordList() {
    return of(customerTagRecord)
  }

  public delCustomer() {
    return this.net.send({
      service: customerController.delCustomer
    })
  }

  public setPerson() {
    return this.net.send({
      service: customerController.setPerson
    })
  }

  public customerApply(param) {
    return this.net.send({
      service: customerController.customerApply,
      params:param
    })
  }
  //获取标签
  public getTagStatistics(){
    return this.net.send({
      service: customerController.getTagStatistics
    })
  }
  public getTagHot(){
    return this.net.send({
      service: customerController.getTagHot
    })
  }
  public getTagActive(){
    return this.net.send({
      service: customerController.getTagActive
    })
  }
  public getTagAdd(){
    return this.net.send({
      service:customerController.getTagAdd

    })
  }
  public getTagCatalog(cursor?){
    return this.net.send({
      service: customerController.getTagCatalog,
      cursor
    })
  }
  public getCustTagList(cursor?){
    return this.net.send({
      service: customerController.getCustTagList,
      cursor
    })
  }
  public getTagDetail(id) {
    return this.net.send({
      service: customerController.getCustomerTagDetail,
      append:[id]
    })
  }
  public getTagExecute(id,cursor?) {
    return this.net.send({
      service: customerController.getTagExecute,
      cursor,
      append:[id,'execute','list']
    })
  }
  public getTagCustomer(id,cursor?){
    return this.net.send({
      service: customerController.getTagCustomer,
      cursor,
      append:[id,'customer','list']
    })
  }
  public getTagPreference(id,cursor?){
    return this.net.send({
      service: customerController.getTagPreference,
      append:[id,'preference'],
      cursor,
    })
  }
  public getTagBasicRecord(id){
    return this.net.send({
      service: customerController.getTagBasicRecord,
      append:[id,'basic']
    })
  }
  public creatTag(param){
    return this.net.send({
      service: customerController.creatTag,
      params:param
    })
  }
  public getTagList(cursor?){
    return this.net.send({
      service: customerController.getTagList,
      cursor,
    })
  }
  public getCustomerGroupList(cursor?) {
    return this.net.send({
      service: customerController.getCustomerGroupList,
      cursor
    })
  }
  public updateGroup(param,id) {
    return this.net.send({
      service: customerController.updateGroup,
      append:[id],
      params:param
    })
  }
  public creatGroup(param) {
    return this.net.send({
      service: customerController.creatGroup,
      params:param
    })
  }
  public delGroup(id) {
    return this.net.send({
      service: customerController.delGroup,
      append:[id]
    })
  }
}
